package com.liujianlei.redis7_study.service;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author tongchen
 * @create 2023-07-04 10:43
 */
@Service
@Slf4j
public class OrderService {
    public static final String ORDER_KRY="order:";
    @Resource
    private RedisTemplate <String,String>redisTemplate;

    public Integer addOrder(){
        //生成订单名称
        int keyId=ThreadLocalRandom.current().nextInt(1000)+1;
        //生成对应的订单号
        String value = UUID.randomUUID().toString();
        redisTemplate.opsForValue().set(ORDER_KRY+keyId, "京东订单："+value);
        //存储订单
        //返回结果
        return keyId;
    }
    public String getOrder(int keyId){
        return redisTemplate.opsForValue().get(ORDER_KRY+keyId);
    }
}
